
var target:Transform;
var zigs:int = 100;
var speed:float = 1f;
var scale:float = 1f;
var startLight:Light;
var endLight:Light;

var perlinTool:PerlinTool;
var oneOverZigs:float;
private var particles:Particle[];

function Start(){
	oneOverZigs = 1f / zigs;
	particleEmitter.emit = false;
	
	particleEmitter.Emit(zigs);
	particles = particleEmitter.particles;
}

function Update(){
	if(perlinTool == null){
		perlinTool = PerlinTool();
	}
	for(var i:int = 0;i<particles.Length;i++){
		var position:Vector3 = Vector3.Lerp(transform.position,target.position,oneOverZigs * i);
		
		var offset:Vector3 = perlinTool.GetOffsetWithTime(speed,position);
		position += (offset * scale * i * oneOverZigs);
		
		particles[i].position = position;
		particles[i].color = Color.white;
		particles[i].energy = 1;
	}
	particleEmitter.particles = particles;
	if(particleEmitter.particleCount >= 2){
		if(startLight)
			startLight.transform.position = particles[0].position;
		if(endLight)
			endLight.transform.position = particles[particles.Length - 1].position;
	}
}